package com.a3dweijing.wetouch2.Util;

import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;

import com.a3dweijing.wetouch2.Common.CallBack;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/3/22. 弹窗生成器
 */

public class AlerDialogHelp
{
    /**
     * @param isCanceledByOut 点击边缘是否消失
     * @param callBack 是否带是，否按钮
     * @return
     */
    public static AlertDialog create(Context context, String title, String msg, boolean isCanceledByOut, @Nullable
    final CallBack callBack)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(title).setMessage(msg);
        if (callBack != null)
        {
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    
                }
            }).setPositiveButton("确定", new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    callBack.doNext(0, null);
                }
            });
        }
        
        AlertDialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(isCanceledByOut);
        return alertDialog;
    }
    /**
     * @param isCanceledByOut 点击边缘是否消失
     * @return
     */
    public static AlertDialog createForList(Context context, String title, final String[] msg, boolean isCanceledByOut,
        @Nullable
        final CallBack callBack)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(title);
        if (callBack != null)
        {
            builder.setItems(msg, new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialogInterface, int i)
                {
                    callBack.doNext(i, null);
                }
            });
        }
        
        AlertDialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(isCanceledByOut);
        return alertDialog;
    }
}
